home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / showtext.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  2KB  |  107 lines

  1. #include "showtext.h"
  2.  
  3. inline void moveto(loc xy, int dir)
  4.     {
  5.     if(dir)
  6.     moveto(xy.Y, getmaxx() - xy.X);
  7.     else
  8.     moveto(xy);
  9.     }
  10. /////////////////////
  11. inline int getmaxx(int dir)
  12.     {
  13.     if(dir) return getmaxy();
  14.     return getmaxx();
  15.     }
  16. ///////////////////
  17. inline int getmaxy(int dir)
  18.     {
  19.     if(dir) return getmaxx();
  20.     return getmaxy();
  21.     }
  22. ////////////////////
  23. int text_width(char* str, ljfont* fnt,
  24.            int zoom_x, int zoom_y)       // correct return len of str, when str is
  25.     {                           // line of deformated characters
  26.     int len = 0;
  27.     char s[2];
  28.     s[1] = '\0';
  29.     int n = strlen(str);
  30.     while(n > 0)
  31.     {
  32.     s[0] = str[n - 1];
  33.     len += fnt->scaledtextsize(s, zoom_x, zoom_y).width();
  34.     n--;
  35.     }
  36.     return len;
  37.     }
  38. //////////////////////////
  39. void ShowText::loadFont(char* fontName)
  40.     {
  41.     delete buffer;
  42.     buffer = new char[5000];
  43.     buffer[0] = '\0';         // end of line
  44.     delete fnt;
  45.     fnt = new ljfont(fontName);
  46.     }
  47. ///////////////////////////
  48. void ShowText::show(loc where, char* string, loc scale, int interval,
  49.             int direction,
  50.             int mode)
  51.     {
  52.     if(direction)
  53.     where = loc(where.Y, getmaxx() - where.X);
  54.  
  55.     int len = 0;
  56.     char st[500];
  57.     strncpy(st, string, 499);
  58.     char* s;
  59.     moveto(where, direction);
  60.     while(1)
  61.     {
  62.     s = strchr(string + len, '\n');
  63.     if(s == NULL)
  64.         {
  65.         drawscaledstr(*fnt, string + len, scale.X, scale.Y,
  66.               mode,    direction);
  67.         break;
  68.         }
  69.     strncpy(st, string + len, s - string - len);
  70.     st[s - string - len] = '\0';
  71.  
  72.     len = s - string + 1;
  73.     moveto(where, direction);
  74.     drawscaledstr(*fnt, st, scale.X, scale.Y,
  75.         mode, direction);
  76.  
  77.     if(direction == HORIZ_DIR)
  78.         where.Y += interval * fnt->scaledtextsize("H!",
  79.                           scale.X, scale.Y).height() / 10;
  80.     else
  81.         where.Y -= interval * fnt->scaledtextsize("H!",
  82.                           scale.X, scale.Y).height() / 10;
  83.     moveto(where, direction);
  84.     }
  85.     }
  86. //////////////////////////////
  87. /*
  88. void main()
  89.     {
  90.     if(!init_KNOW_HOW())
  91.         return;
  92.  
  93.     ShowText s;
  94.     s.loadFont("hv08a.sfp");
  95.  
  96.     s.show(loc(100, 100), "12345678901234567890", loc(2, 2));
  97.  
  98.     line(0, 100, 200, 100);
  99.     line(100, 0, 100, 200);
  100.  
  101.     line(0, 200, 200, 200);
  102.     line(200, 0, 200, 200);
  103.  
  104.     close_KNOW_HOW();
  105.     closegraph();
  106.     }
  107. */